# Define here the models for your scraped baseitems
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.html

# import scrapy


# class WuliuNewsItem(scrapy.Item):
#     # define the fields for your baseitems here like:
#     # name = scrapy.Field()
#     pass

from datetime import datetime

from wuliu_news.api.dicts.biaozhun_dict import BiaozhunPayloadKeys
from wuliu_news.api.dicts.news_dict import NewsPayloadKeys
from wuliu_news.api.dicts.qyalfx_dict import QyalfxPayloadKeys
from wuliu_news.api.dicts.zhishujiedu_dict import ZhishuJieduPayloadKeys
from wuliu_news.baseitems.baseitem import BaseItem
from wuliu_news.settings import BASE_WEBSITE


class WuliuNewsItem(BaseItem):
    """新闻资讯"""
    moduleid: int               # 21
    file: str                   # index
    action: str                 # add
    itemid: int                 # 0
    forward: str                # http://wuliu.akng.net/admin.php?rand=76&moduleid=21&action=add&catid=47044
    catid: int                  # 47044
    title: str
    level: int                  # 1
    style: str
    thumb: str
    linkurl: str
    content: str
    save_remotepic: int         # 1
    clear_link: int             # 1
    introduce_length: int       # 120
    thumb_no: str
    subtitle: str
    introduce: str
    author: str
    copyfrom: str
    fromurl: str
    tag: str
    voteid: str
    status: int                 # 3
    note: str
    addtime: str                # 2021-12-16 17:57:12
    areaid: int                 # 0
    hits: int                   # 0
    fee: str
    template: str
    submit: str                 # 确 定

    def __init__(self, cat_id, moduleid=21, **kwargs):
        BaseItem.__init__(self, **kwargs)

        self.catid = cat_id
        self.moduleid = moduleid
        self.file = "index"
        self.action = "add"
        self.itemid = 0

        self.submit = "确 定"
        self.status = 3
        self.save_remotepic = 1
        self.clear_link = 0
        self.introduce_length = 120
        self.level = 1

        bw = BASE_WEBSITE.rstrip('/')
        self.forward = f"{bw}/admin.php?rand=76&moduleid={self.moduleid}&action={self.action}&catid={self.catid}"

        self.addtime = str(datetime.now())[:19]

    @property
    def values(self):
        """
        转换 baseitems 与 payload 之间的 key
        :return:
        """
        values = dict()
        for k, v in self.__dict__.items():
            values[NewsPayloadKeys.get(k, k)] = v
        return values


class WuliuBiaozhunNewsItem(BaseItem):
    """标准咨询"""
    moduleid: int                   # 7
    file: str                       # index
    action: str                     # add
    itemid: int                     # 0
    forward: str                    # http://wuliu.akng.net/admin.php?action=left&bb=3
    catid: int                      # 6
    title: str                      # 标准要闻test1
    level: int                      # 0
    style: str
    tag: str
    thumb: str
    chname: str
    enname: str
    content: str                    # &nbsp;标准要闻test1
    save_remotepic: int             # 1
    thumb_no: str
    status: int                     # 3
    note: str
    addtime: str                    # 2021-12-17 23:54:40
    areaid: int                     # 0
    hits: int                       # 0
    fee: str
    template: str
    submit: str                     # 确 定

    def __init__(self, cat_id, moduleid=7, **kwargs):
        BaseItem.__init__(self, **kwargs)

        self.catid = cat_id
        self.moduleid = moduleid
        self.file = "index"
        self.action = "add"
        self.itemid = 0

        self.submit = "确 定"
        self.status = 3
        self.save_remotepic = 1
        self.level = 0

        bw = BASE_WEBSITE.rstrip('/')
        self.forward = f"{bw}/admin.php?moduleid={self.moduleid}&action={self.action}&catid={self.catid}"

        self.addtime = str(datetime.now())[:19]

    @property
    def values(self):
        """
        转换 baseitems 与 payload 之间的 key
        :return:
        """
        values = dict()
        for k, v in self.__dict__.items():
            values[BiaozhunPayloadKeys.get(k, k)] = v
        return values


class WuliuQyalfxItem(BaseItem):
    """企业案例分享"""
    moduleid: int           # 55
    file: str               # shenbao
    action: str             # add
    itemid: int             # 0
    forward: str            # http://wuliu.akng.net/admin.php?moduleid=55&file=shenbao&anlitype=1
    catid: int              # 1
    hd_id: int              # 3
    title: str
    level: int              # 0
    style: str
    thumb: str
    linkurl: str
    content: str
    # save_remotepic: int  # 1
    introduce_length: int  # 120
    thumb_no: str
    subtitle: str
    introduce: str
    author: str
    copyfrom: str
    fromurl: str
    tag: str
    voteid: str
    status: int             # 3
    note: str
    addtime: str            # 2021-12-16 17:57:12
    areaid: int             # 0
    hits: int               # 0
    fee: str
    template: str
    submit: str             # 确 定

    def __init__(self, cat_id=1, moduleid=55, **kwargs):
        BaseItem.__init__(self, **kwargs)

        self.catid = cat_id
        self.moduleid = moduleid
        self.file = "shenbao"
        self.action = "add"
        self.itemid = 0
        self.hd_id = 3
        self.submit = "确 定"
        self.status = 3
        # self.save_remotepic = 1
        self.introduce_length = 120
        self.level = 0

        bw = BASE_WEBSITE.rstrip('/')
        self.forward = f"{bw}/admin.php?moduleid={self.moduleid}&file={self.file}&anlitype=1"

        self.addtime = str(datetime.now())[:19]

    @property
    def values(self):
        """
        转换 baseitems 与 payload 之间的 key
        :return:
        """
        values = dict()
        for k, v in self.__dict__.items():
            values[QyalfxPayloadKeys.get(k, k)] = v
        return values


class WuliuJiageZhishuItem(BaseItem):
    """价格指数"""
    moduleid: int
    file: str       # index
    action: str     # add
    itemid: int     # 0
    forward: str    # http://wuliu.akng.net/admin.php?moduleid=42&action=add
    catid: int
    title: str
    level: int
    style: str
    thumb: str
    linkurl: str
    content: str
    save_remotepic: int
    introduce_length: int
    thumb_no: str
    subtitle: str
    introduce: str
    author: str
    copyfrom: str
    fromurl: str
    tag: str
    voteid: str
    status: int
    note: str
    addtime: str
    areaid: int
    hits: int
    fee: str
    template: str
    submit: str             # 确 定

    def __init__(self, cat_id, moduleid=42, **kwargs):
        BaseItem.__init__(self, **kwargs)

        self.catid = cat_id
        self.moduleid = moduleid
        self.file = "index"
        self.action = "add"
        self.itemid = 0
        self.submit = "确 定"
        self.status = 3
        self.save_remotepic = 1
        self.introduce_length = 120
        self.level = 0

        bw = BASE_WEBSITE.rstrip('/')
        self.forward = f"{bw}/admin.php?moduleid={self.moduleid}&action={self.action}"

        self.addtime = str(datetime.now())[:19]

    @property
    def values(self):
        """
        转换 baseitems 与 payload 之间的 key
        :return:
        """
        values = dict()
        for k, v in self.__dict__.items():
            values[ZhishuJieduPayloadKeys.get(k, k)] = v
        return values
